#ifndef QIMAGETRANSFORMER_H
#define QIMAGETRANSFORMER_H
#include <opencv2\opencv.hpp>
#include <opencv2\core\core.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\calib3d\calib3d.hpp>
#include "tools.hpp"
#include <QObject>
#include <QImage>
#include <QDebug>

static QImage cvMat_to_QImage(const cv::Mat &mat) {
	switch (mat.type())
	{
		// 8-bit, 4 channel
	case CV_8UC4:
	{
		QImage image(mat.data, mat.cols, mat.rows, mat.step, QImage::Format_RGB32);
		return image;
	}

	// 8-bit, 3 channel
	case CV_8UC3:
	{
		QImage image(mat.data, mat.cols, mat.rows, mat.step, QImage::Format_RGB888);
		return image.rgbSwapped();
	}

	// 8-bit, 1 channel
	case CV_8UC1:
	{
		static QVector<QRgb>  sColorTable;
		// only create our color table once
		if (sColorTable.isEmpty())
		{
			for (int i = 0; i < 256; ++i)
				sColorTable.push_back(qRgb(i, i, i));
		}
		QImage image(mat.data, mat.cols, mat.rows, mat.step, QImage::Format_Indexed8);
		image.setColorTable(sColorTable);
		return image;
	}

	default:
		qDebug("Image format is not supported: depth=%d and %d channels\n", mat.depth(), mat.channels());
		break;
	}
	return QImage();
}
class QImageTransformer : public QObject
{
	Q_OBJECT
private:
	queue<unsigned char*> *spe_frame_data_0;
	queue<unsigned char*> *spe_frame_data_1;
	queue<unsigned char*> *spe_frame_merge_data_0;
	queue<unsigned char*> *spe_frame_merge_data_1;
	cv::Mat ui_mask;
	QImage *image_data_all;
	QImage *image_data_single;
	int channle_num;
	unsigned char * one_channel_data;
	unsigned char * one_channel_data_trans;

	bool require_flag = false;
	int get_flag;
public:
	explicit QImageTransformer(QObject *parent = 0);
	~QImageTransformer();
	bool continue_signal = true;
	RawInfo rawinfo;
	void getOneChannelData(unsigned char * input, int channel_num, int length, unsigned char * output, int c);
public slots:
	void receive(queue<unsigned char*> * _spe_frame_data_0, queue<unsigned char*> * _spe_frame_data_1, queue<unsigned char*> *_spe_frame_merge_data_0, queue<unsigned char*> *_spe_frame_merge_data_1, QImage *_image_data_all, QImage * _image_data_single);
	//void transformer();
	void transformer(int num);
	void change_channle(int num);
signals:
	void single_transformed();
	void all_transformed();
	
};

#endif
